//
//  HBTXViewController.m
//  YaDiuDiu
//
//  Created by 欧洪飞 on 2017/8/30.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "HBTXViewController.h"

@interface HBTXViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *textNum;
@property (weak, nonatomic) IBOutlet UILabel *labDZMoney;
@property (weak, nonatomic) IBOutlet UILabel *labSXF;

@end

@implementation HBTXViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self showNav:@"提现到余额"];
    _labDZMoney.text = @"";
    _textNum.delegate = self;
    [self loadData];
    
}
#pragma - mark UITextFieldDelegate
-(void)textFieldDidEndEditing:(UITextField *)textField{
    _labDZMoney.text = [NSString stringWithFormat:@"￥%@",textField.text];
}

- (IBAction)clickAllTX:(id)sender {
    _textNum.text = _labMoney.text;
    _labDZMoney.text = _labMoney.text;
}
//红包提现
- (IBAction)clickSureTX:(id)sender {
    NSString *str = [NSString stringWithFormat:@"%@890d69e502d1d37a9e84335ccefece57",[user objectForKey:@"token2"]];
    NSString *token = [LCMD5Tool md5:str];
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:token forKey:@"verifyToken"];
    [parmas setObject:[user objectForKey:@"userid"] forKey:@"userid"];
    [parmas setObject:_textNum.text forKey:@"num"];
    NSLog(@"parmas:%@",parmas);
    NSString *url = [NSString stringWithFormat:@"%@/App/Usercenter/eedCashWithdrawal",urlHead];
    
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"红包提现res:%@",responseObject);
        NSString *state = [NSString stringWithFormat:@"%li",[[responseObject objectForKey:@"status"] integerValue]];
        NSString *msg = [responseObject objectForKey:@"msg"];
        if ([state integerValue] == 200) {
            [SVProgressHUD showSuccessWithStatus:state];
        }else{
            [SVProgressHUD showErrorWithStatus:msg];
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
    }];
}
//红包转入余额页面
- (void)loadData{
    NSString *str = [NSString stringWithFormat:@"%@890d69e502d1d37a9e84335ccefece57",[user objectForKey:@"token2"]];
    NSString *token = [LCMD5Tool md5:str];
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:token forKey:@"verifyToken"];
    [parmas setObject:[user objectForKey:@"userid"] forKey:@"userid"];
    NSLog(@"parmas:%@",parmas);
    NSString *url = [NSString stringWithFormat:@"%@/App/Usercenter/userRedBalance",urlHead];
    
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"红包转入余额res:%@",responseObject);
        
        _labMoney.text = [responseObject objectForKey:@"money"];
        NSString *str = @"%";
        _labSXF.text = [NSString stringWithFormat:@"实际到账（平台手续费：%li%@）",[[responseObject objectForKey:@"serviceCharge"] integerValue],str];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
    }];
    
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
